package com.panopset.refactorsf;

import static com.panopset.Util.log;
import static com.panopset.Util.x;

import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFileChooser;

import com.panopset.sf.Windoc;

/**
 * File path persistent container.
 *
 * @author Karl Dinwiddie
 *
 */
public final class PanFile extends AbstractPanFile {

    /**
    *
    * @param borderTitle
    *            Border title.
    * @param toolTipText
    *            Tool tip text.
    */
   public PanFile(final Windoc wd, final String borderTitle, final String toolTipText) {
       this(wd, borderTitle, toolTipText, "");
   }

   /**
    *
    * @param borderTitle
    *            Border title.
    * @param toolTipText
    *            Tool tip text.
    * @param defaultValue
    *            Default value.
    */
   public PanFile(final Windoc wd, final String borderTitle, final String toolTipText,
           final String defaultValue) {
       this(wd, borderTitle, toolTipText, defaultValue, true);
   }   
   
   public PanFile(final Windoc wd, final String borderTitle, final String toolTipText,
           final String defaultValue, boolean isPersistent) {
       super(wd, borderTitle, toolTipText, defaultValue, isPersistent);
   }

    @Override
    protected LayoutManager createLayout() {
        return new GridLayout(1, 1);
    }

    @Override
    protected boolean isValid(final String valueToCheck) {
        return true;
    }

    @Override
    protected String createPrompter() {
        return x("file");
    }

    @Override
    protected int getFileSelectionMode() {
        return JFileChooser.FILES_ONLY;
    }

    @Override
    protected void create() {
        try {
            FileWriter fw = new FileWriter(getFile());
            fw.write("");
            fw.flush();
            fw.close();
        } catch (IOException e) {
            log(e);
        }
    }
}
